Installing and Configuring GCP SDK
This lesson discusses getting started with CLI.
Installing Google Cloud SDK#
GCP also provides a command-line interface using the SDK. The CLI interface provides more functionality over GUI or a website. In fact, there are some tasks that cannot be accomplished using the website, and these tasks/functionalities need to be done via CLI only.
So, let’s see how to install and configure Google Cloud CLI.
Installation without Docker#
There are multiple ways to install the SDK. The recommended way to install anything is to open up official documentation and look at the installation method for your system. The official documentation is always updated for installation. If you don’t have Docker and are willing to install it natively on the OS, feel free to use the Quickstart Installation guide for your OS and follow the steps for your systems.
If you want to use the Docker version of SDK, that’s also fine. Since Docker abstracts all the dependencies and works on all the systems, Docker is the quickest way to get started. However, you need to learn docker if you haven’t learned it yet.
If you want to know the basics to get started with Docker quickly, here is the Docker course.
Installation using Docker#
- Pull the latest SDK image from the container repository using the following command.
docker pull gcr.io/google.com/cloudsdktool/cloud-sdk:latest
- Verify the image by running the following command.
docker run --rm gcr.io/google.com/cloudsdktool/cloud-sdk:latest gcloud version
The output will be similar to:
Google Cloud SDK 317.0.0
alpha 2020.10.30
app-engine-go 1.9.71
app-engine-java 1.9.82
app-engine-python 1.9.91
app-engine-python-extras 1.9.91
beta 2020.10.30
bigtable
bq 2.0.62
cbt 0.9.0
cloud-datastore-emulator 2.1.0
cloud-firestore-emulator 1.11.9
cloud-spanner-emulator 1.1.1
core 2020.10.30
datalab 20190610
gsutil 4.54
kubectl 1.16.13
pubsub-emulator 0.1.2
That’s it. Only two steps to get started with the SDK using docker.
You can also start using gcloud on the ephemeral terminal given at the end of this lesson.
- Type
gcloud versionto cross-check the installation.
Configuring Cloud SDK#
To start using the Cloud SDK we need to configure it. The command gcloud init is used to configure the initial settings for the SDK.
Configuring Docker GCP SDK
While using Docker, the state or configuration is stored in the Docker volume.
docker run -ti --name gcloud-config gcr.io/google.com/cloudsdktool/cloud-sdk gcloud auth login
Once you’ve successfully completed authentication, credentials are preserved in the volume of the gcloud-config container. You need to pass this volume to execute authenticated gcloud commands.
docker run --rm --volumes-from gcloud-config gcr.io/google.com/cloudsdktool/cloud-sdk gcloud config list
Configuration without Docker
- If you installed SDK without Docker, type,
gcloud init
This will initialize the configuration steps starting from the login and setting up the default project.
root@educative:/# gcloud init
Welcome! This command will take you through the configuration of gcloud.
Your current configuration has been set to: [default]
You can skip diagnostics next time by using the following flag:
gcloud init --skip-diagnostics
Network diagnostic detects and fixes local network connection issues.
Checking network connection...done.
Reachability Check passed.
Network diagnostic passed (1/1 checks passed).
You must log in to continue. Would you like to log in (Y/n)? Y
Go to the following link in your browser:
https://accounts.google.com/o/oauth2/auth?client_id=32555940559.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth&code_challenge=NURRInX6Sabjgx4hh4Ml5D6T5ppTnYLa2HL0h485R3s&code_challenge_method=S256&access_type=offline&response_type=code&prompt=select_account
Enter verification code: )
If you are using an OS native shell/terminal, gcloud will open the default browser and ask you to log in. If not, a link is provided, and you need to open it in the browser and copy and paste the code into the terminal.
Once the code is verified, you will be logged in with your email. The command will continue to wait for input regarding the configuration of the default project and default region.
You are logged in as: [gcpcourseeducative@gmail.com].
Pick cloud project to use:
[1] gcp-educative-project-cli
[2] gcp-headstart-educative-308308
[3] gcp-headstart-educative-unique
[4] mythical-geode-308208
[5] Create a new project
Please enter numeric choice or text value (must exactly match list
item): 2
Your current project has been set to: [gcp-headstart-educative-308308].
Do you want to configure a default Compute Region and Zone? (Y/n)? Y
Which Google Compute Engine zone would you like to use as project
default?
If you do not specify a zone via a command line flag while working
with Compute Engine resources, the default is assumed.
[1] us-east1-b
[2] us-east1-c
[3] us-east1-d
[4] us-east4-c
[5] us-east4-b
[6] us-east4-a
[7] us-central1-c
[8] us-central1-a
[9] us-central1-f
[10] us-central1-b
[11] us-west1-b
[12] us-west1-c
[13] us-west1-a
[14] europe-west4-a
[15] europe-west4-b
[16] europe-west4-c
[17] europe-west1-b
[18] europe-west1-d
[19] europe-west1-c
[20] europe-west3-c
[21] europe-west3-a
[22] europe-west3-b
[23] europe-west2-c
[24] europe-west2-b
[25] europe-west2-a
[26] asia-east1-b
[27] asia-east1-a
[28] asia-east1-c
[29] asia-southeast1-b
[30] asia-southeast1-a
[31] asia-southeast1-c
[32] asia-northeast1-b
[33] asia-northeast1-c
[34] asia-northeast1-a
[35] asia-south1-c
[36] asia-south1-b
[37] asia-south1-a
[38] australia-southeast1-b
[39] australia-southeast1-c
[40] australia-southeast1-a
[41] southamerica-east1-b
[42] southamerica-east1-c
[43] southamerica-east1-a
[44] asia-east2-a
[45] asia-east2-b
[46] asia-east2-c
[47] asia-northeast2-a
[48] asia-northeast2-b
[49] asia-northeast2-c
[50] asia-northeast3-a
Did not print [27] options.
Too many options [77]. Enter "list" at prompt to print choices fully.
Please enter numeric choice or text value (must exactly match list
item): 1
Your project default Compute Engine zone has been set to [us-east1-b].
You can change it by running [gcloud config set compute/zone NAME].
Your project default Compute Engine region has been set to [us-east1].
You can change it by running [gcloud config set compute/region NAME].
Created a default .boto configuration file at [/root/.boto]. See this file and
[https://cloud.google.com/storage/docs/gsutil/commands/config] for more
information about configuring Google Cloud Storage.
Your Google Cloud SDK is configured and ready to use!
* Commands that require authentication will use gcpcourseeducative@gmail.com by default
* Commands will reference project `gcp-headstart-educative-308308` by default
* Compute Engine commands will use region `us-east1` by default
* Compute Engine commands will use zone `us-east1-b` by default
Run `gcloud help config` to learn how to change individual settings
This gcloud configuration is called [default]. You can create additional configurations if you work with multiple accounts and/or projects.
Run `gcloud topic configurations` to learn more.
Some things to try next:
* Run `gcloud --help` to see the Cloud Platform services you can interact with. And run `gcloud help COMMAND` to get help on any gcloud command.
* Run `gcloud topic --help` to learn about advanced features of the SDK like arg files and output formatting
root@educative:/#
Running on the Educative interactive shell
The interactive shell below is a GCP instance itself, and GCP SDK is preinstalled on it. You can use the below terminal to execute the above commands.
Projects shown here might be different from your output.
Using cloud shell#
There is one more way to use SDK without installing it. The GCP dashboard provides an inbuilt cloud shell that comes prebuilt with Cloud SDK. Click on the terminal icon in the right corner. We used the same cloud shell in the IAM: Hands-On lesson.
Once you have the SDK CLI ready by any method you can try different gcloud commands. Try gcloud info to get information about the SDK.
Next, we will start using some Cloud SDK commands, like setting the default project, changing the default configurations, etc. Also, you will learn the command structure of the Cloud SDK. So, practice the CLI and move onto the next lesson.
Quiz
Cloud SDK In Action